<style>
    pre {outline: 1px solid #ccc; padding: 5px; margin: 5px; }
    .string { color: green; }
    .number { color: darkorange; }
    .boolean { color: blue; }
    .null { color: magenta; }
    .key { color: red; }
</style>

<!-- index弹窗 -->
<form id="index-form" lay-filter="index-form" class="layui-form model-form" style="height:500px; overflow:auto !important;">
    <div class="layui-form-item layui-form-text" style="width: 430px; height:460px; margin-top: -20px">
        <pre class="layui-code" id="data"></pre>
    </div>
</form>

<script>
    layui.use(['layer', 'admin'], function () {
        let layer = layui.layer;
        let admin = layui.admin;
        // 回显user数据
        let indexName = admin.getTempData('indexName');
        if (indexName) {
            admin.req('api-search/admin/index/'+indexName, {}, function (data) {
                layer.closeAll('loading');
                if (0 == data.resp_code) {
                    $('#data').html(syntaxHighlight(data.datas));
                } else {
                    layer.msg('获取索引信息失败', {icon: 2, time: 500});
                }
            }, 'GET');
        }
    });

    function syntaxHighlight(json) {
        if (typeof json != 'string') {
            json = JSON.stringify(json, undefined, 2);
        }
        json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
        return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function(match) {
            var cls = 'number';
            if (/^"/.test(match)) {
                if (/:$/.test(match)) {
                    cls = 'key';
                } else {
                    cls = 'string';
                }
            } else if (/true|false/.test(match)) {
                cls = 'boolean';
            } else if (/null/.test(match)) {
                cls = 'null';
            }
            return '<span class="' + cls + '">' + match + '</span>';
        });
    }
</script>